<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="/css/public.css" media="all">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script src="/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
    <script src="/lib/jq-module/jquery.particleground.min.js" charset="utf-8"></script>

    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>

<body>

    <div class="layui-container">

        <!-- <div class=" layui-col-md5 layui-col-md-offset1 "> -->
        <div class="layui-form layuimini-form">
            <form class="layui-form" layui-filter="Arma-improt">
                <div class="layui-row layui-col-space5">
                    <label class="layui-form-label required" style="width: 135px;">请选择上传文件：</label>
                    <input type="hidden" name="excel" id="inp-1">
                    <div class="layui-input-block">
                        <button type="button" class="layui-btn" id="durl">
                            <i class="layui-icon">&#xe67c;</i>上传文件
                        </button>
                    </div>
                </div>
                <div class="layui-input-block" style="margin-top: 10px;margin-left: 170px;">
                    <div style="width: 95px;">
                        <div class="layui-progress layui-progress-big" lay-showpercent="yes" lay-filter="demo">
                            <div class="layui-progress-bar layui-bg-green" lay-percent=""></div>
                        </div>
                    </div>
                </div>
            </form>
        </div>

    </div>

    <!-- </div> -->





    <script>
        layui.use(['form', 'upload', 'element'], function () {
            var form = layui.form,
                upload = layui.upload,
                element = layui.element,
                layer = layui.layer,
                $ = layui.$;




            // 常规使用 - 普通图片上传
            var uploadInst = upload.render({
                elem: '#durl'//绑定按钮呢的元素
                , accept: 'file'//普通文件
                , exts: 'xlsx'//只允许上传压缩文件
                , url: 'http://localhost:8080/medical/armarium/import' //此处用的是第三方的 http 请求演示，实际使用时改成您自己的上传接口即可。

                , done: function (res) {
                    if (res.code == 0) {
                        // $("#demo1").attr("src", res.data.url);
                        // $("#pic").val(res.data.url);  // 把上传之后的图片地址 存到隐藏域  表单提交的时候 传到后台
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.msg("上传成功", { icon: 6, time: 2000 });
                        parent.layer.close(iframeIndex);
                    }
                    //如果上传失败
                    if (res.code == 1) {
                        return layer.msg('上传失败', { icon: 5, time: 4000 });
                    }
                    //上传成功的一些操作
                    //……
                    // $('#demoText').html(''); //置空上传失败的状态
                }
                // , error: function () {
                //     //演示失败状态，并实现重传
                //     var demoText = $('#demoText');
                //     demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                //     demoText.find('.demo-reload').on('click', function () {
                //         uploadInst.upload();
                //     });
                // }
                //进度条
                , progress: function (n, elem, e) {
                    element.progress('demo', n + '%'); //可配合 layui 进度条元素使用
                    if (n == 100) {
                        layer.msg('上传完毕', { icon: 1, time: 2000 });
                    }
                }
            });

        });

    </script>

</body>

</html>